package com;



import java.util.HashMap;
import java.util.Map;


import com.admin.User;
import com.admin.UserService;

import com.Constants;
import com.util.MD5Encryption;


public class LoginAction extends UserService {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String usercode;
	private String passwd;
	
	public String execute() throws Exception {
	
		User user = (User)session.get(Constants.USER);
		if(user!=null) {
			
			return "main";
		}else {
			
			return "success";
		}
		
		
	}
	
	
	
	
	public void dologin(){
		try {
			Map<String,String> map = new HashMap<String,String>();
			map.put("Usercode", usercode);
			map.put("Password", MD5Encryption.toMD5(passwd));
			User loginuser =selectLoginUser(map);
			//鐧诲綍鎴愬姛
			if (loginuser != null) {
				if (loginuser.getForbidden() == 1) {
					message = "账号已停用，请联系管理员";
					ajaxJson(message);
					return;
				}
				
				session.put(Constants.USER, loginuser);
				
				ajaxJson("0");
			}else {
				
				message = "账号密码错误";
				ajaxJson(message);
				return;
			}
			
			
		}catch(Exception e) {
			
			e.printStackTrace();
		} 
		return;
	}

	
	 




	


	






	public String getUsercode() {
		return usercode;
	}

	public void setUsercode(String usercode) {
		this.usercode = usercode;
	}

	public String getPasswd() {
		return passwd;
	}

	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}

	
}